package com.kuaimacode.kframework.api.controller;

import com.kuaimacode.kframework.common.Constant;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpServletRequest;
import java.util.Optional;

/**
 * @author qinyong
 * @Title:
 * @Package com.kuaimacode.kframework.api.controller
 * @Description: created by IntelliJ IDEA
 * @date 2019-03-10 17:53
 */
public class BaseController {

    @Autowired
    protected HttpServletRequest request;

    /**
     * 获取request中的userid
     * @return
     */
    public Long getUserId() {
        return (Long) request.getAttribute("userId");
    }

    /**
     * 获取分站ID（session中）
     * @return
     */
    public String getAgentId() {
        return Optional.ofNullable(request.getSession().getAttribute("agent_id"))
                .orElse(Constant.DEFAULT_AGENT_ID).toString();
    }
}
